package conexion;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;




public class Conexion {
	private static Connection con;
	private static Statement stmt;
	
	private static String user="root";
	private static String password="aus2011";
	private static String BD="mydb2";
	private static String host="localhost";
	
	public static Connection conectar() throws Exception{
		
		try{
			
			if (con == null){ //verificamos si esta conectado
				
				Class.forName("com.mysql.jdbc.Driver");//importamos el driver
				
				con=DriverManager.getConnection("jdbc:mysql://"+host+"/" + BD, user, password); //obtenemos la conexion a la BD
				
				stmt=con.createStatement();
				
			}
		}catch(ClassNotFoundException e){
			System.out.println(e);
		}catch(SQLException c){
			System.out.println(c);
		}
		return con;
	}
	
	public static void desconectar() throws Exception{
		try{
			if (con!=null){
				stmt.close();
				con.close();
				con=null;
			}
		}catch(SQLException e){
			System.out.println(e);
		}
	}
	

}
